﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using CommDll;

namespace SupervisionCodeCollection
{
    /// <summary>
    /// ClassName:frmPasswordChange
    /// Version:1.0
    /// Date:2019-05-23
    /// Author:seanouyang
    /// </summary>
    /// <remarks>
    /// 本类是一WinForm 窗体,本窗体主要为实现库房确定
    /// </remarks>    
    public partial class frmStockPlaceConfirm : DevComponents.DotNetBar.OfficeForm
    {
        #region 01.自定义属性
        public int m_nKind = 1; // 1:盘点
        public string m_strInfo = ""; // 库房信息
        #endregion

        #region 02.自定义方法
        /// <summary>
        /// 初始化库房信息
        /// </summary>
        private void _initPharmacy()
        {
            string strSql = "";
            strSql = @"select Name + '|' + Code + '|' + Kind  as StockPlace
                        from
                        (
                        select Code,Name,'药库' as Kind from TH_Warehouse
                        Union all
                        select Code,Name,'药房' as Kind from TH_Pharmacy
                        )A order by Kind,Code";
            strSql = string.Format(strSql, AppInfo.m_UserInfo.m_strDeptCode);
            DataTable dt = CommFun._openSql_dt(strSql);
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    lbInfo.Items.Add(dr[0].ToString());
                } 
            }
        }
        #endregion
        public frmStockPlaceConfirm()
        {
            InitializeComponent(); 
        }

        #region 03.系统事件方法

        private void frmStockPlaceConfirm_Load(object sender, EventArgs e)
        {
            switch (m_nKind)
            {
                case 1:
                    lblTitle.Text = "库房盘点-库房确定";
                    this.Text = lblTitle.Text;
                    _initPharmacy();
                    break;
                default:
                    break;
            }
        }

        private void cbbStockPlace_DrawItem(object sender, DrawItemEventArgs e)
        {
            // 重绘使可以调整行距
            CommFun._cbbDrawItem(sender, e);
        }

        private void listBox1_MeasureItem(object sender, MeasureItemEventArgs e)
        {
            this.lbInfo.ItemHeight = 22;
        }

        private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();
            e.DrawFocusRectangle();
            e.Graphics.DrawString(lbInfo.Items[e.Index].ToString(), e.Font, new SolidBrush(Color.Black), e.Bounds);
        }
        
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (lbInfo.SelectedIndex >= 0)
            {
                m_strInfo = lbInfo.Text.Trim();
                this.DialogResult = DialogResult.OK;
            }
        }

        private void btnReturn_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        

        
    }
}